package com.osfw.system.entity.monitor;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.osfw.framework.core.entity.BasicEntity;
import com.osfw.framework.enums.OnlineStatus;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import java.util.Date;

/**
 * 当前在线会话 sys_user_online
 */
@Data
@Accessors(chain = true)
public class SysUserOnline extends BasicEntity {
    private static final long serialVersionUID = 1L;

    /* 用户会话id */
    @TableId(value = "sessionId_", type = IdType.ASSIGN_ID)
    private String sessionId;

    /* 部门名称 */
    @TableField(value = "dept_name_")
    private String deptName;

    /* 登录名称 */
    @TableField(value = "login_name_")
    private String loginName;

    /* 登录IP地址 */
    @TableField(value = "ipaddr_")
    private String ipaddr;

    /* 登录地址 */
    @TableField(value = "login_location_")
    private String loginLocation;

    /* 浏览器类型 */
    @TableField(value = "browser_")
    private String browser;

    /* 操作系统 */
    @TableField(value = "os_")
    private String os;

    /* session创建时间 */
    @TableField(value = "start_timestamp_")
    private Date startTimestamp;

    /* session最后访问时间 */
    @TableField(value = "last_access_time_")
    private Date lastAccessTime;

    /* 超时时间，单位为毫秒 */
    @TableField(value = "expire_time_")
    private Long expireTime;

    /* 在线状态 */
    @TableField(value = "status_")
    private OnlineStatus status = OnlineStatus.on_line;


    @Override
    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
                .append("sessionId", getSessionId())
                .append("loginName", getLoginName())
                .append("deptName", getDeptName())
                .append("ipaddr", getIpaddr())
                .append("loginLocation", getLoginLocation())
                .append("browser", getBrowser())
                .append("os", getOs())
                .append("status", getStatus())
                .append("startTimestamp", getStartTimestamp())
                .append("lastAccessTime", getLastAccessTime())
                .append("expireTime", getExpireTime())
                .toString();
    }
}
